
/*
 Initial code taken from : Quodlibet.be
 */
package org.iabako.server.tools.pdftable;


import org.apache.pdfbox.pdmodel.interactive.documentnavigation.outline.PDOutlineItem;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class PdfRow {
    PDOutlineItem bookmark;
    List<PdfCell> cells;
    float height;
    private boolean noLine;

    public PdfRow(List<PdfCell> cells, float height) {
        this.cells = cells;
        this.height = height;
    }

    public PdfRow(float height) {
        this.height = height;
    }

    public void addCell(PdfCell cell) {
        if (cells == null) cells = new ArrayList();
        cells.add(cell);
    }

    public float getHeight(float horizontalMargin, float verticalMargin) throws IOException {
        float maxHeight = height;
        for (PdfCell cell : this.cells) {
            //int lines = cell.getParagraph(horizontalMargin).getLines().size();
            //float cellHeight = lines * cell.getFontSize() + (verticalMargin * 2) + (lines - 1) * 1.2f;
            float cellHeight = PdfWriterHelper.getHeightOfCell(cell, horizontalMargin, verticalMargin, cell.getFontSize());
            if (cellHeight > maxHeight) {
                maxHeight = cellHeight;
            }
        }
        return maxHeight;
    }

    public float getLineHeight() throws IOException {
        return height;

    }

    public void setHeight(float height) {
        this.height = height;
    }

    public List<PdfCell> getCells() {
        return cells;
    }

    public int getColCount() {
        return cells.size();
    }

    public void setCells(List<PdfCell> cells) {
        this.cells = cells;
    }

    public float getWidth() {
        float totalWidth = 0;
        for (PdfCell cell : cells) {
            totalWidth += cell.getWidth();
        }
        return totalWidth;
    }

    public PDOutlineItem getBookmark() {
        return bookmark;
    }

    public void setBookmark(PDOutlineItem bookmark) {
        this.bookmark = bookmark;
    }

    public boolean isNoLine() {
        return noLine;
    }

    public void setNoLine(boolean noLine) {
        this.noLine = noLine;
    }
}
